Learn R Programming

bnlearn (version 4.9.1)

node operations: Manipulate nodes in a graph

Description

Add, remove and rename nodes in a graph.

Usage

# add and remove nodes.
add.node(x, node)
remove.node(x, node)

# re-label nodes. rename.nodes(x, names) # S4 method for bn nodes(object) <- value # S4 method for bn.fit nodes(object) <- value

Value

add.node(), remove.node() and rename.nodes() return an updated bn object.

Arguments

x

an object of class bn for add.node() and remove.node(); an object of class bn or bn.fit for rename.nodes().

object

an object of class bn or bn.fit.

node

a character string, the label of a node.

value, names

a vector of character strings, the new set of labels that wll be used as to rename the nodes.

Author

Marco Scutari

Details

add.node() adds a new (isolated) node to an existing bn object.

remove.node() removes a node from a bn object.

rename.nodes() replaces the node labels with new ones, relabelling the whole node set. The assignment method for nodes() is an alias of rename.nodes().

Examples

Run this code
dag = random.graph(LETTERS[1:5])
add.node(dag, "Z")
remove.node(dag, "A")

nodes(dag)
nodes(dag) = LETTERS[6:10]
nodes(dag)

Run the code above in your browser using DataLab